﻿using System;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;

namespace BugReporter
{
    public partial class BugReporterForm : Form
    {
        string m_lang, m_project, m_version, m_exception, m_exceptionMsg;

        public BugReporterForm() {
            InitializeComponent();
        }

        public BugReporterForm( String project, String version, String exception, String exceptionMsg ) {
            InitializeComponent();
            m_lang = "C-Sharp";
            m_project = project;
            m_version = version;
            m_exception = exception;
            m_exceptionMsg = exceptionMsg;
        }

        /// <summary>
        /// Reads path of default browser from registry
        /// </summary>
        /// <returns></returns>
        private static string GetDefaultBrowserPath() {
            string key = @"htmlfile\shell\open\command";
            RegistryKey registryKey =
            Registry.ClassesRoot.OpenSubKey( key, false );
            // get default browser path
            return ( (string)registryKey.GetValue( null, null ) ).Split( '"' )[1];
        }

        private void noBTN_Click( object sender, EventArgs e ) {
            this.Hide();
        }

        private void yesBTN_Click( object sender, EventArgs e ) {
            // Create data to post.
            string postData = "http://www.gams-apps.com/bugReporter.aspx?project=" + m_project + "&lang=" + m_lang + "&version=" + m_version
                + "&exception=" + m_exception + "&excMsg=" + m_exceptionMsg;

            Process.Start( GetDefaultBrowserPath(), postData );

            this.Hide();
        }
    }
}
